<style type="text/css">
<!--
	 .yeucauthaydoi{
		border-collapse: collapse;
		margin: auto;
		margin-top: 50px;
		margin-bottom: 50px;
}
	tr{
		border: 1px solid;
}
	.up:hover, .down:hover{
		cursor: pointer;
}
-->
</style>
<?php echo $this->render('frontend_common/header.phtml'); ?>
<div id="Content">
<div style="width: 100%">
<form action="customoder" method="post">
<table class="yeucauthaydoi" cellpadding="10px" id="<?php echo $this->giohoaid_customoder ?>table">
<tr>
	<th width="150px">Tên hoa</th>
	<th width="120px">Số lượng</th>
	<th width="40px"></th>
	<th width="100px"></th>
	<th>Giá tiền</th>
</tr>
<?php $list=$this->list_ct_giohoa;
		$listtenhoa=$this->list_tenhoa;
	foreach ($list as $ct_giohoa)
	{
?>
	<tr id="<?php echo $ct_giohoa['hoa_id'] ?>idhoa" style="border: 1px solid">
		<td align="right"><?php echo $listtenhoa[$ct_giohoa['hoa_id']]['tenhoa'] ?> : </td>
		<td style="padding-right: 0px">
			<input disabled="disabled" class="slhoa" type="text" name="<?php echo $ct_giohoa['hoa_id'] ?>" type="text" value="<?php echo $listtenhoa[$ct_giohoa['hoa_id']]['slhoa']?>" style="height: 30px">
			<input class="slgoc" readonly="readonly" type="hidden" name="<?php echo $ct_giohoa['hoa_id'] ?>" type="text" value="<?php echo $ct_giohoa['slhoa']?>" style="height: 30px">
		</td>
		<td style="padding-left: 0">
			<img class="up" src="<?php echo $this->baseUrl('/images/system/blue_up.png') ?>" style="width: 15px; height: 15px"/><br/>
			<img class="down" src="<?php echo $this->baseUrl('/images/system/blue_down.png') ?>" style="width: 15px; height: 15px"/>
		</td>
		<td>
			<?php
			 if(!empty($listtenhoa[$ct_giohoa['hoa_id']]['slthaydoi']))
			 {
			 	echo '<label  style="display:block; float: left;" class="thembot">';
			 	if((int)$listtenhoa[$ct_giohoa['hoa_id']]['slthaydoi']<0)
			 		echo 'Thêm';
			 	else 
		 			echo 'Giảm';	
			 	echo '</label>';
			 }			
			else 
				echo '<label  style="display:none;float: left;" class="thembot"></label>'; 
			echo (!empty($listtenhoa[$ct_giohoa['hoa_id']]['slthaydoi'])) ?	 '<label  style="display:block; float: left; margin-left: 8px;" class="slthaydoi">'.abs((int)$listtenhoa[$ct_giohoa['hoa_id']]['slthaydoi']).'</label>'
				 		:	'<label  style="display:none; float: left; margin-left: 8px;" class="slthaydoi">0</label>' ;
			 ?>
		</td>
		<td style="text-align: right;" class="dongia">
			<?php echo  $listtenhoa[$ct_giohoa['hoa_id']]['dongia'];?>
		</td>
	</tr>

	
<?php }?>
<tr>
	<td colspan="3">
		<input type="button" value="Về giỏ hàng" onclick="window.location='<?php echo $this->url(array('controller'=>'cart','action'=>'index'));?>'"/>
	</td>
	<td>
		<label>Đơn giá giỏ hoa : </label>
	</td>
	<td style="text-align: right;">
		
		<label class="tongtien" >
			<?php
				if(!empty($this->abc))
					echo $this->abc;
				else 
			 		echo $this->dongia;
			 ?>
		</label>
	</td>
</tr>
</table>
</form>
<?php echo $this->render('frontend_common/footer.phtml'); ?>
<script type="text/javascript">
	$(document).ready(function(){
		$('.up').click(function(){
			var giohoa_id_truoc= $(this).parents('table').attr('id');//id gio hoa
			var giohoa_id_sau = (parseInt)(giohoa_id_truoc);//id gio hoa
			var id = $(this).parent().parent().attr('id');//id tr
			var slhientai=$('#' +id+' .slhoa').attr('value');
			slhientai=(parseInt)(slhientai)+1;
			$('#' +id+' .slhoa').attr('value',slhientai);
			
			//xu li cho biet them/bot so luong bao nhieu
			var slgoc=$('#' +id+' .slgoc').attr('value');
			var slthaydoi=(parseInt)(slhientai)-(parseInt)(slgoc);
			if(slthaydoi<0)
			{
				$('#'+id+' .thembot').html('Giảm');
				$('#'+id+' .slthaydoi').html(Math.abs(slthaydoi));
				$('#'+id+' .slthaydoi').css("display","block"); 
				$('#'+id+' .thembot').css("display","block");
			}
			else
				if(slthaydoi>0)
				{
					$('#'+id+' .thembot').html('Thêm');
					$('#'+id+' .slthaydoi').html(slthaydoi);
					$('#'+id+' .slthaydoi').css("display","block"); 
					$('#'+id+' .thembot').css("display","block");
				}
				else
				{
					$('#'+id+' .slthaydoi').css("display","none"); 
					$('#'+id+' .thembot').css("display","none");
				}
			
			var data = "";
			data += '&id='+(parseInt)(id)+'&sl='+slhientai+'&id_sp='+giohoa_id_sau;
			$.ajax({
		           url :'<?php echo $this->baseUrl('/cart/tinhtiencustomorder'); ?>',
		           data : data,
		           dataType :"json",
		           type : 'POST',
		           success : function(result){
		        	   var giacu=$('#'+id +' .dongia').html();
			           giacu=parseInt(giacu);
			           var tongtien=$('.tongtien').html();
			           tongtien=parseInt(tongtien);
			           tongtien=tongtien-giacu+result;
		        	   $("#"+id+' .dongia').html(result);
		        	   $('.tongtien').html(tongtien);
			           //$('#'+id +' .dongia').html(result['giamoi']);
			           //$('#tongtien').html(result['tongtien']);
		           }
		      	});
		});


		$('.down').click(function(){
			var giohoa_id=(parseInt)($(this).parents('table').attr('id'));
			var id = $(this).parent().parent().attr('id');
			var slhientai=$('#' +id+' .slhoa').attr('value');
			slhientai=(parseInt)(slhientai)-1;
			if(slhientai<0)
				return;
			$('#' +id+' .slhoa').attr('value',slhientai);
			
			//xu li cho biet them/bot so luong bao nhieu
			var slgoc=$('#' +id+' .slgoc').attr('value');
			var slthaydoi=(parseInt)(slhientai)-(parseInt)(slgoc);

			if(slthaydoi<0)
			{
				
				$('#'+id+' .thembot').html('Giảm');
				$('#'+id+' .slthaydoi').html(Math.abs(slthaydoi));
				$('#'+id+' .slthaydoi').css("display","block"); 
				$('#'+id+' .thembot').css("display","block");
			}
			else
				if(slthaydoi>0)
				{
					$('#'+id+' .thembot').html('Thêm');
					$('#'+id+' .slthaydoi').html(slthaydoi);
					$('#'+id+' .slthaydoi').css("display","block"); 
					$('#'+id+' .thembot').css("display","block");
				}
				else
				{
					$('#'+id+' .slthaydoi').css("display","none"); 
					$('#'+id+' .thembot').css("display","none");
				}
			var data = "";
			data += '&id='+(parseInt)(id)+'&sl='+slhientai+'&id_sp='+giohoa_id;
			$.ajax({
		           url :'<?php echo $this->baseUrl('/cart/tinhtiencustomorder'); ?>',
		           data : data,
		           dataType :"json",
		           type : 'POST',
		           success : function(result){
			           var giacu=$('#'+id +' .dongia').html();
			           giacu=parseInt(giacu);
			           var tongtien=$('.tongtien').html();
			           tongtien=parseInt(tongtien);
			           tongtien=tongtien-giacu+result;
		        	   $('#'+id +' .dongia').html(result);
		        	   $('.tongtien').html(tongtien);
		           }
		      	});
		});
	});
</script>